<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2019-06-28
  Time: 9:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String pash = request.getContextPath();
    String basepash = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + pash + "/";
%>
<html>
<head>
    <base href="<%=basepash%>">
    <%@include file="/publs.jsp"%>
    <title>Title</title>
</head>
<body>
<div id="root">

    <Modal title="添加客户" v-model="showhidess" @on-ok="insert">
        <i-form :label-width="80">
            <form-item label="姓名">
                <i-input v-model="userts.username"></i-input>
            </form-item>
            <%--<form-item label="性别">--%>
                <%--<Radio-Group v-model="asdadasd" v-model="userts.sex">--%>
                    <%--<Radio :label="1">--%>
                        <%--<Icon type="md-male"></Icon>--%>
                        <%--<span>男</span>--%>
                    <%--</Radio>--%>
                    <%--<Radio :label="2">--%>
                        <%--<Icon type="md-female"></Icon>--%>
                        <%--<span>女</span>--%>
                    <%--</Radio>--%>
                <%--</Radio-Group>--%>
            <%--</form-item>--%>
            <%--<form-item label="年龄">--%>
                <%--<i-input v-model="userts.age"></i-input>--%>
            <%--</form-item>--%>
            <form-item label="手机号">
                <i-input v-model="userts.phone"></i-input>
            </form-item>
            <form-item label="门店名称">
                <i-input  v-model="userts.mendian"></i-input>
            </form-item>
            <form-item label="门店地址">
                <i-input v-model="userts.dizhi"></i-input>
            </form-item>
            <%--<form-item label="会员类型">--%>
                <%--<i-select v-model="userts.userTypeid" style="width: 100px">--%>
                    <%--<i-option v-for="item in shuzu" :value="item.typeid">{{item.memberName}}</i-option>--%>
                <%--</i-select>--%>
            <%--</form-item>--%>
        </i-form>
    </Modal>

    <Modal v-model="detailsModel" :title="asdasdasdjiaqina" width="75%">
        <i-table :data="detailsData" :columns="detailsColumns"></i-table>
    </Modal>


    <Modal title="修改客户" v-model="showhidesssssssss" @on-ok="update">
        <i-form :label-width="80">
            <form-item label="姓名">
                <i-input v-model="userts.username"></i-input>
            </form-item>
            <%--<form-item label="性别">--%>
                <%--<Radio-Group v-model="asdadasd" v-model="userts.sex">--%>
                    <%--<Radio :label="1">--%>
                        <%--<Icon type="md-male"></Icon>--%>
                        <%--<span>男</span>--%>
                    <%--</Radio>--%>
                    <%--<Radio :label="2">--%>
                        <%--<Icon type="md-female"></Icon>--%>
                        <%--<span>女</span>--%>
                    <%--</Radio>--%>
                <%--</Radio-Group>--%>
            <%--</form-item>--%>
            <%--<form-item label="年龄">--%>
                <%--<i-input type="number" v-model="userts.age"></i-input>--%>
            <%--</form-item>--%>
            <form-item label="手机号">
                <i-input v-model="userts.phone"></i-input>
            </form-item>
            <form-item label="门店名称">
                <i-input  v-model="userts.mendian"></i-input>
            </form-item>
            <form-item label="门店地址">
                <i-input v-model="userts.dizhi"></i-input>
            </form-item>
        </i-form>
    </Modal>


    <Modal v-model="asdadasdas" width="80%" title="个人记录">
        <i-table :data="orderData" :columns="orderColumns" @on-row-dblclick="searchDetailssssssssssssssss">

        </i-table>
    </Modal>




    <i-button @click="insertas" type="primary" style="margin-left: 50px;margin-top: 20px;">添加</i-button>
        <Row  style="margin-top: 10px;margin-bottom: -20px">
            <i-col>
                <i-form :label-width="80" :inline="true">
                    <form-item label="姓名">
                        <i-input v-model="name"></i-input>
                    </form-item>
                    <form-item label="手机号">
                        <i-input type="number" v-model="shoujihao"></i-input>
                    </form-item>
                    <%--<form-item label="门店名称">--%>
                        <%--<i-input  v-model="mendian"></i-input>--%>
                    <%--</form-item>--%>
                    <%--<form-item label="门店地址">--%>
                        <%--<i-input v-model="dizhi"></i-input>--%>
                    <%--</form-item>--%>
                    <%--<form-item label="类型">--%>
                        <%--<i-select v-model="id" style="width: 100px">--%>
                            <%--<i-option value="0">请选择</i-option>--%>
                            <%--<i-option v-for="item in shuzu" :value="item.typeid">{{item.memberName}}</i-option>--%>
                        <%--</i-select>--%>
                    <%--</form-item>--%>
                    <i-button type="primary" icon="ios-search" @click="select">查询</i-button>
                </i-form>
            </i-col>
        </Row>



    <i-table  :height="heights" style="margin-top:20px;margin-right: 50px;margin-left: 50px;" :data="datas" :columns="colunmsss" border  @on-row-dblclick="searchDetails">
        <%--<template slot="sexs" slot-scope="{row}">--%>
            <%--<span>{{row.sex==1?"男":"女"}}</span>--%>
        <%--</template>--%>
        <template slot="leixings" slot-scope="{row}">
            <span>{{row.membertype.MemberName}}</span>
        </template>
        <template slot="caozuo" slot-scope="{row}">
            <i-button size="small" type="primary" @click="updates(row)" >修改</i-button>
        </template>
    </i-table>
        <page :total="totals"  @on-change="onchenge" :page-Size="pageSize" show-sizer :page-size-opts="[4,8,12]" @on-page-size-change="onPageSizeChange"></page>
</div>
<script>
    let _this = null;
    new Vue({
        el:"#root",
        data:{
            datas:[],
            asdasdasdjiaqina:"",
            showhidess:false,
            asdadasd:1,
            detailsData:[],
            detailsColumns: [
                {title:"编号",key:"id"},
                {title:"药品编号",key:"drugsid"},
                {title:"数量",key:"number"},
                {title:"价格/元",key:"price"},
                {title:"合计/元",render(h,{row}){
                        return h("span",row.number*row.price)
                    }},
                {title:"购买时间",key:"atime"}
            ],
            detailsModel:false,
            asdadasdas:false,
            colunmsss:[
                {
                    title:"姓名",
                    key:"username"
                }
                // {
                //     title:"性别",
                //     key:"sex",
                //     slot:"sexs",
                //     sortable: true
                // }
                // ,{
                //     title:"年龄",
                //     key:"age",
                //     sortable:true
                // }
                ,{
                    title:"手机号",
                    key:"phone"
                },{
                    title:"门店名称",
                    key:"mendian"
                },{
                    title:"门店地址",
                    key:"dizhi"
                },
                // {
                //     title:"客户类型",
                //     // key:"leixing",
                //     // slot:"leixings"
                //     render(h,{row}){
                //         return h("span",row.membertype.memberName);
                //     }
                // },
                {
                    title:"操作",
                    slot:"caozuo"
                }
            ],
            showhidesssssssss:false,
            heights:0,
            totals:0,
            pageNo:0,
            pageSize:8,
            name:"",
            shoujihao:"",
            id:0,
            shuzu:[],
            userts:{},
            orderData:[],
            orderColumns:[
                {title:"编号",key:"id"},
                {title:"订单号",key:"orideridid"},
                // {title:"购买人",key:"goumairen"},
                // {title:"购买公司",key:"mendinans"},
                {title:"购买时间",key:"goumaishijian"},
                {title:"销售/退货",key:"types"},
                // {title:"操作",slot:"operation"}
            ],
        },
        methods:{
            onchenge(size){
                this.pageNo = size;
                this.select();
            },
            onPageSizeChange(size){
                this.pageSize = size;
                this.select();
            },
            select(){
                axios.get("/kuhu/select?name="+this.name+"&shoujihao="+this.shoujihao+"&pageSize="+this.pageSize+"&pageNo="+this.pageNo).then(({data})=>{
                    _this.datas = data.obj.list;
                    _this.totals = data.obj.tatle;
                    _this.heights = data.obj.list.length * 48 + 40;
                })
            },
            selectType(){
                axios.get("/kuhu/selecttype").then(({data})=>{
                    _this.shuzu = data.obj;
                })
            },
            insertas(){
                _this.showhidess = true;
            },
            insert(){
                axios.post("/kuhu/insert",this.userts).then((({data})=>{
                    iview.Message.info(data.msg);
                    _this.userts = {};
                    _this.select()
                }))
            },
            updates(row){
                Object.assign(_this.userts,row)
                _this.showhidesssssssss = true;
            },
            update(){
                axios.post("/kuhu/update",this.userts).then((({data})=>{
                    iview.Message.info(data.msg);
                    _this.select()
                    _this.userts = {};
                }))
            },
            searchDetails(row,index){
                    this.searchAll(row);
            },
            searchAll(row){
                console.log(row)
                let name1 = "";//购买人
                let name2 = "";//随机数
                let name3 = "";//购买公司id
                let name4 = "";//状态

                axios.get("/zOnInSearch/searchOrder?name1="+row.username+"&name2=&name3="+row.userid+"&name4=")
                    .then(({data})=>{
                        _this.orderData = data.obj;
                        _this.asdadasdas = true;
                    })
            },
            searchDetailssssssssssssssss(row){
                axios.post("/zOnInSearch/searchDetails?orderIds="+row.id)
                    .then(({data})=>{
                        this.detailsModel = true;
                        this.detailsData = data.obj;
                        let a = this.detailsData;
                        let jiaqian = 0;
                        for (let i = 0; i < a.length; i++) {
                            let as = a[i].number*a[i].price;
                            jiaqian = jiaqian + as;
                        }
                        this.asdasdasdjiaqina = jiaqian;
                        if(this.asdasdasdjiaqina==0){
                            this.asdasdasdjiaqina = "明细:总价格为0元";
                        }else{
                            this.asdasdasdjiaqina = "明细---总价格"+this.asdasdasdjiaqina+"元";
                        }
                    })
            }
        },
        mounted(){
            this.select();
            this.selectType();
        },
        created(){
            _this = this;
        }
    })
</script>
</body>
</html>
